import request from '@/utils/request'

/**
 * 
 * @param {string} param.username  用户账号
 * @param {string} param.password  用户密码
 * @returns 
 */
export function login(param) {
  return request({
    url: '/login',
    method: 'post',
    data: {
      username: param.username,
      password: param.password
    }
  })
}

export function getInfo(token) {
  return request({
    url: '/vue-admin-template/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}

/**
 * 获取微信用户列表
 * @param {number} param.currPage 当前页
 * @param {number} param.pageSize 页容
 * @param {number} param.nickname 昵称
 * @param {number} param.phone    手机号
 */
export function GetUserList(param) {
  return request({
    url: '/wxuser/query',
    method: 'post',
    data: {
      currPage: param.currPage,
      pageSize: param.pageSize,
      /* itemList: [
        {
          name: "nickname",
          op: "like",
          value1: param.nickname
        },
        {
          name: "phone",
          op: "like",
          value1: param.phone
        },
      ] */
    }
  })
}

/**
 * 设置为业务员
 * @param {string} param.address 地址
 * @param {string} param.name 姓名
 * @param {number} param.phone 电话
 * @param {string} param.wxId 微信Id
 * @param {string} param.commissionRatio 比例
 */
export function SetSaleMan(param) {
  return request({
    url: '/saleMan/add',
    method: 'post',
    data: {
      address: param.address,
      name: param.name,
      phone: param.phone,
      wxId: param.wxId,
      commissionRatio: param.commissionRatio
    }
  })
}

/**
 * 修改业务员信息
 *  @param {string} param.id 业务员id
 */
export function UpdateSaleMan(param) {
  console.log(param)
  return request({
    url: '/saleMan/update',
    method: 'post',
    data: {
      address: param.address,
      name: param.name,
      phone: param.phone,
      id: param.id,
      commissionRatio: param.commissionRatio
    }
  })
}
/**
 * 获取业务员列表
 * @param {number} param.currPage 当前页
 * @param {number} param.pageSize 页容
 */
export function GetSalesManList(param) {
  return request({
    url: '/saleMan/query',
    method: 'post',
    data: {
      currPage: param.currPage,
      pageSize: param.pageSize,
    }
  })
}

/**
 * 禁用业务员
 * @param {number} id 用户id
 * @param {string} saleManState 状态
 */
export function SetSalesManStatus(id, saleManState = 'NORMAL') {
  return request({
    url: '/saleMan/updateStates',
    method: 'post',
    data: {
      id,
      saleManState
    }
  })
}

/**
 * 获取管理员列表
 */
export function GetAdminList(param) {
  return request({
    url: '/user/query',
    method: 'post',
    data: {
      currPage: param.currPage,
      pageSize: param.pageSize
    }
  })
}

/**
 * 新增管理员
 * @param { string } param.nickname 名字
 * @param { string } param.username 账号
 * @param { string } param.password 密码
 * @param { string } param.confirmPassword 确认密码
 * @param { string } param.roleIdList 角色身份   ADMIN: '超级管理员' USER: '普通管理员'
 */
export function AddAdmin(param) {
  return request({
    url: '/user/register',
    method: 'post',
    data: {
      nickname: param.nickname,
      username: param.username,
      password: param.password,
      confirmPassword: param.confirmPassword,
      roleIdList: param.roleIdList
    }
  })
}

/**
 * 修改管理员信息
 */
export function UpdateAdmin(param) {
  return request({
    url: '/user/info/update',
    method: 'post',
    data: {
      id: param.id,
      nickname: param.nickname,
      roleIdList: param.roleIdList
    }
  })
}

/**
 * 删除管理员
 * @param {id} 管理员id
*/
export function DeleteAdmin(id) {
  return request({
    url: '/user/delete',
    method: 'post',
    data: {
      id
    }
  })
}

/**
 * 修改状态
 * @param {number} id     管理员id
 * @param {string} states 状态
 */
export function SetAdminStatus(id, states) {
  return request({
    url: '/user/updateStates',
    method: 'post',
    data: {
      id,
      states
    }
  })
}
